< previous page page_362 next page >

Page 362
Starting a New Class Module
First, create a new Standard EXE project in Visual Basic. Then, select Add Class Module from the Project menu. This action creates a new class module with the default name of Class1 and opens the class module's Code window, as shown in Figure 16.1.
0362-01.jpg
Figure 16.1
By using class modules in your VB applications,
you can create your own custom program objects.
After creating the new class module, you should give the class a unique and descriptive name. The name of a class module is much more significant than the name of a standard code module because you actually use the class name within program code. Many developers like to use the letter c or cls to indicate a class name. This simple class example will be an employee class, so name the class module clsEmployee.
To name a class, bring up the Properties window for the class module. Press F4 while the Code window is open, or right-click the class module in the Project Explorer and choose Properties from the context menu.
Adding Properties to the Class
After the class module has been created, you can add your own properties. Properties in your own classes are used in the same way as those of controls, for storing and retrieving information. You can add properties to your class in two ways: by using public variables and property procedures.
Public Variables
Using public variables is the easiest way to create properties. You just enter them in the declarations section of the class module. For the sample clsEmployee, you can add a few simple properties with the following code:
Public FirstName As String
Public LastName As String
Public Salary As Currency
Public DateHired As Date

 
< previous page page_362 next page >